package com.ruoyi.park.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.park.domain.BuiPublicArea;
import com.ruoyi.park.service.IBuiPublicAreaService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 公共区域Controller
 *
 * @author cjie
 * @date 2021-07-20
 */
@Api(tags = " 公共区域")
@RestController
@RequestMapping("/buiPublicArea")
public class BuiPublicAreaController extends BaseController {
    @Autowired
    private IBuiPublicAreaService buiPublicAreaService;

    /**
     * 查询公共区域列表
     */
    @ApiOperation(value="查询公共区域列表", notes="查询公共区域列表")
    @PreAuthorize(hasPermi = "park:buiPublicArea:list")
    @GetMapping("/list")
    public TableDataInfo list(BuiPublicArea buiPublicArea) {
        startPage();
        List<BuiPublicArea> list = buiPublicAreaService.selectBuiPublicAreaList(buiPublicArea);
        return getDataTable(list);
    }

    /**
     * 导出公共区域列表
     */
    @ApiOperation(value="导出公共区域列表", notes="导出公共区域列表")
    @PreAuthorize(hasPermi = "park:buiPublicArea:export")
    @Log(title = "公共区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuiPublicArea buiPublicArea) throws IOException {
        List<BuiPublicArea> list = buiPublicAreaService.selectBuiPublicAreaList(buiPublicArea);
        ExcelUtil<BuiPublicArea> util = new ExcelUtil<BuiPublicArea>(BuiPublicArea.class);
        util.exportExcel(response, list, "公共区域数据");
    }
    /**
     * 获取公共区域详细信息
     */
    @ApiOperation(value="获取公共区域详细信息", notes="获取公共区域详细信息")
    @PreAuthorize(hasPermi = "park:buiPublicArea:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(buiPublicAreaService.selectBuiPublicAreaById(id));
    }

    /**
     * 新增公共区域
     */
    @ApiOperation(value="新增公共区域", notes="新增公共区域")
    @PreAuthorize(hasPermi = "park:buiPublicArea:add")
    @Log(title = "公共区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuiPublicArea buiPublicArea) {
        return toAjax(buiPublicAreaService.insertBuiPublicArea(buiPublicArea));
    }

    /**
     * 修改公共区域
     */
    @ApiOperation(value="修改公共区域", notes="修改公共区域")
    @PreAuthorize(hasPermi = "park:buiPublicArea:edit")
    @Log(title = "公共区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuiPublicArea buiPublicArea) {
        return toAjax(buiPublicAreaService.updateBuiPublicArea(buiPublicArea));
    }

    /**
     * 删除公共区域
     */
    @ApiOperation(value="删除公共区域", notes="删除公共区域")
    @ApiImplicitParam(name = "ids", value = "公共区域ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:buiPublicArea:remove")
    @Log(title = "公共区域", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(buiPublicAreaService.deleteBuiPublicAreaByIds(ids));
    }
}
